// Fill out your copyright notice in the Description page of Project Settings.


#include "PlayerCharacter.h"
#include "GameFramework\CharacterMovementComponent.h"

APlayerCharacter::APlayerCharacter()
{
	SprintSpeed = 1200;
	CurrentStatus = EStatus::ES_Normal;
}

void APlayerCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) 
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAction("Sprint",IE_Pressed,this,&APlayerCharacter::BeginSprint);
	PlayerInputComponent->BindAction("Sprint",IE_Released,this,&APlayerCharacter::EndSprint);
	PlayerInputComponent->BindAction("Run",IE_Pressed,this,&APlayerCharacter::BeginRun);
	PlayerInputComponent->BindAction("Run",IE_Released,this,&APlayerCharacter::EndRun);

}

void APlayerCharacter::SetStatus(EStatus Status) 
{
	CurrentStatus = Status;
	switch (CurrentStatus)
	{
	case EStatus::ES_Normal:
		GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
		break;
	case EStatus::ES_Run:
		GetCharacterMovement()->MaxWalkSpeed = RunSpeed;
		break;
	case EStatus::ES_Sprint:
		GetCharacterMovement()->MaxWalkSpeed = SprintSpeed;
	default:
		break;
	}
}

void APlayerCharacter::BeginSprint() 
{
	SetStatus(EStatus::ES_Sprint);
}

void APlayerCharacter::EndSprint()
{
	SetStatus(EStatus::ES_Normal);
}

void APlayerCharacter::BeginRun() 
{
	SetStatus(EStatus::ES_Run);
}

void APlayerCharacter::EndRun() 
{
	SetStatus(EStatus::ES_Normal);
}